var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var Assert = (function () {
    function Assert() { }
    Assert.equal = function equal(actual, expected) {
        if (actual !== expected) {
            throw 'equal failed when passed ' + '{' + (typeof actual) + '} "' + actual + '" and ' + '{' + (typeof expected) + '} "' + expected + '"';
        }
    };
    Assert.notEqual = function notEqual(actual, expected) {
        if (actual === expected) {
            throw 'notEqual failed when passed ' + '{' + (typeof actual) + '} "' + actual + '" and ' + '{' + (typeof expected) + '} "' + expected + '"';
        }
    };
    Assert.equalNumber = function equalNumber(expected, actual) {
        if (Math.abs(expected - actual) > 0.00000000000001) {
            throw 'equal failed when passed ' + '{' + (typeof expected) + '} "' + expected + '" and ' + '{' + (typeof actual) + '} "' + actual + '"';
        }
    };
    Assert.notEqualNumber = function notEqualNumber(expected, actual) {
        if (Math.abs(expected - actual) <= 0.00000000000001) {
            alert(Math.abs(expected - actual).toString());
            throw 'notEqual failed when passed ' + '{' + (typeof expected) + '} "' + expected + '" and ' + '{' + (typeof actual) + '} "' + actual + '"';
        }
    };
    Assert.isTrue = function isTrue(actual) {
        if (!actual) {
            throw 'isTrue failed when passed ' + '{' + (typeof actual) + '} "' + actual + '"';
        }
    };
    Assert.isFalse = function isFalse(actual) {
        if (actual) {
            throw 'isFalse failed when passed ' + '{' + (typeof actual) + '} "' + actual + '"';
        }
    };
    Assert.throws = function throws(actual) {
        var isThrown = false;
        try  {
            actual();
        } catch (ex) {
            isThrown = true;
        }
        if (!isThrown) {
            throw 'did not throw an error';
        }
    };
    Assert.fail = function fail() {
        throw 'fail';
    };
    return Assert;
})();
var tUnit;
(function (tUnit) {
    var Test = (function () {
        function Test() {
            this.testDefinitions = [];
            this.RESERVED_FUNCTION_NAMES = [
                'constructor', 
                'setUp', 
                'tearDown', 
                'testFixtureSetUp', 
                'testFixtureTearDown'
            ];
        }
        Test.prototype.addTestClass = function (testClass, name) {
            if (typeof name === "undefined") { name = 'Tests'; }
            this.testDefinitions.push(new TestDefintion(testClass, name));
        };
        Test.prototype.isReservedFunctionName = function (functionName) {
            if (this.RESERVED_FUNCTION_NAMES.indexOf(functionName) >= 0) {
                return true;
            }
            return false;
        };
        Test.prototype.run = function () {
            var testResult = new TestResult();
            for(var i = 0; i < this.testDefinitions.length; ++i) {
                var testClass = this.testDefinitions[i].testClass;
                var testName = this.testDefinitions[i].name;
                if (typeof testClass['testFixtureSetUp'] === 'function') {
                    try  {
                        testClass['testFixtureSetUp']();
                    } catch (err) {
                        testResult.errors.push(new TestDescription('testFixtureSetUp for ' + testName, 'N/A', err));
                        continue;
                    }
                }
                for(var prop in testClass) {
                    if (!this.isReservedFunctionName(prop)) {
                        if (typeof testClass[prop] === 'function') {
                            if (typeof testClass['setUp'] === 'function') {
                                try  {
                                    testClass['setUp']();
                                } catch (err) {
                                    testResult.errors.push(new TestDescription('setUp for ' + testName, prop, err));
                                    continue;
                                }
                            }
                            try  {
                                testClass[prop]();
                                testResult.passes.push(new TestDescription(testName, prop, 'OK'));
                            } catch (err) {
                                testResult.errors.push(new TestDescription(testName, prop, err));
                            }
                            if (typeof testClass['tearDown'] === 'function') {
                                try  {
                                    testClass['tearDown']();
                                } catch (err) {
                                    testResult.errors.push(new TestDescription('tearDown for ' + testName, prop, err));
                                }
                            }
                        }
                    }
                }
                if (typeof testClass['testFixtureTearDown'] === 'function') {
                    try  {
                        testClass['testFixtureTearDown']();
                    } catch (err) {
                        testResult.errors.push(new TestDescription('testFixtureTearDown for ' + testName, 'N/A', err));
                    }
                }
            }
            return testResult;
        };
        Test.prototype.showResults = function (target, result) {
            var template = '<article>' + '<h1>' + this.getTestResult(result) + '</h1>' + '<p>' + this.getTestSummary(result) + '</p>' + '<section id="tsFail">' + '<h2>Errors</h2>' + '<ul class="bad">' + this.getTestResultList(result.errors) + '</ul>' + '</section>' + '<section id="tsOkay">' + '<h2>Passing Tests</h2>' + '<ul class="good">' + this.getTestResultList(result.passes) + '</ul>' + '</section>' + '</article>';
            target.innerHTML = template;
        };
        Test.prototype.getTestResult = function (result) {
            return result.errors.length === 0 ? 'Test Passed' : 'Test Failed';
        };
        Test.prototype.getTestSummary = function (result) {
            return 'Total tests: <span id="tsUnitTotalCout">' + (result.passes.length + result.errors.length).toString() + '</span>. ' + 'Passed tests: <span id="tsUnitPassCount" class="good">' + result.passes.length + '</span>. ' + 'Failed tests: <span id="tsUnitFailCount" class="bad">' + result.errors.length + '</span>.';
        };
        Test.prototype.getTestResultList = function (testResults) {
            var list = '';
            var group = '';
            var isFirst = true;
            for(var i = 0; i < testResults.length; ++i) {
                var result = testResults[i];
                if (result.testName !== group) {
                    group = result.testName;
                    if (isFirst) {
                        isFirst = false;
                    } else {
                        list += '</li></ul>';
                    }
                    list += '<li>' + result.testName + '<ul>';
                }
                list += '<li>' + result.funcName + '(): ' + this.encodeHtmlEntities(result.message) + '</li>';
            }
            return list + '</ul>';
        };
        Test.prototype.encodeHtmlEntities = function (input) {
            var entitiesToReplace = {
                '&': '&amp;',
                '<': '&lt;',
                '>': '&gt;'
            };
            input.replace(/[&<>]/g, function (entity) {
                return entitiesToReplace[entity] || entity;
            });
            return input;
        };
        return Test;
    })();
    tUnit.Test = Test;    
    var TestContext = (function () {
        function TestContext() { }
        TestContext.prototype.setUp = function () {
        };
        TestContext.prototype.tearDown = function () {
        };
        TestContext.prototype.testFixtureSetUp = function () {
        };
        TestContext.prototype.testFixtureTearDown = function () {
        };
        return TestContext;
    })();
    tUnit.TestContext = TestContext;    
    var TestClass = (function (_super) {
        __extends(TestClass, _super);
        function TestClass() {
            _super.apply(this, arguments);

        }
        return TestClass;
    })(TestContext);
    tUnit.TestClass = TestClass;    
    var FakeFunction = (function () {
        function FakeFunction(name, delgate) {
            this.name = name;
            this.delgate = delgate;
        }
        return FakeFunction;
    })();
    tUnit.FakeFunction = FakeFunction;    
    var Fake = (function () {
        function Fake(obj) {
            for(var prop in obj) {
                if (typeof obj[prop] === 'function') {
                    this[prop] = function () {
                    };
                } else {
                    this[prop] = null;
                }
            }
        }
        Fake.prototype.create = function () {
            return this;
        };
        Fake.prototype.addFunction = function (name, delegate) {
            this[name] = delegate;
        };
        Fake.prototype.addProperty = function (name, value) {
            this[name] = value;
        };
        return Fake;
    })();
    tUnit.Fake = Fake;    
    var TestDefintion = (function () {
        function TestDefintion(testClass, name) {
            this.testClass = testClass;
            this.name = name;
        }
        return TestDefintion;
    })();    
    var TestError = (function () {
        function TestError(name, message) {
            this.name = name;
            this.message = message;
        }
        return TestError;
    })();    
    var TestDescription = (function () {
        function TestDescription(testName, funcName, message) {
            this.testName = testName;
            this.funcName = funcName;
            this.message = message;
        }
        return TestDescription;
    })();
    tUnit.TestDescription = TestDescription;    
    var TestResult = (function () {
        function TestResult() {
            this.passes = [];
            this.errors = [];
        }
        return TestResult;
    })();
    tUnit.TestResult = TestResult;    
    var Assert = (function () {
        function Assert() { }
        Assert.areIdentical = function areIdentical(actual, expected) {
            if (actual !== expected) {
                throw 'areIdentical failed when passed ' + '{' + (typeof actual) + '} "' + actual + '" and ' + '{' + (typeof expected) + '} "' + expected + '"';
            }
        };
        Assert.areNotIdentical = function areNotIdentical(actual, expected) {
            if (actual === expected) {
                throw 'areNotIdentical failed when passed ' + '{' + (typeof actual) + '} "' + actual + '" and ' + '{' + (typeof expected) + '} "' + expected + '"';
            }
        };
        Assert.isTrue = function isTrue(actual) {
            if (!actual) {
                throw 'isTrue failed when passed ' + '{' + (typeof actual) + '} "' + actual + '"';
            }
        };
        Assert.isFalse = function isFalse(actual) {
            if (actual) {
                throw 'isFalse failed when passed ' + '{' + (typeof actual) + '} "' + actual + '"';
            }
        };
        Assert.isTruthy = function isTruthy(actual) {
            if (!actual) {
                throw 'isTrue failed when passed ' + '{' + (typeof actual) + '} "' + actual + '"';
            }
        };
        Assert.isFalsey = function isFalsey(actual) {
            if (actual) {
                throw 'isFalse failed when passed ' + '{' + (typeof actual) + '} "' + actual + '"';
            }
        };
        Assert.throws = function throws(actual) {
            var isThrown = false;
            try  {
                actual();
            } catch (ex) {
                isThrown = true;
            }
            if (!isThrown) {
                throw 'did not throw an error';
            }
        };
        Assert.fail = function fail() {
            throw 'fail';
        };
        return Assert;
    })();
    tUnit.Assert = Assert;    
})(tUnit || (tUnit = {}));
//@ sourceMappingURL=tUnit.js.map
